package com.sailfish.springbootdemo.controller.db1;

import com.sailfish.springbootdemo.pojo.Result;
import com.sailfish.springbootdemo.pojo.db1.Brand;
import com.sailfish.springbootdemo.pojo.db1.BrandType;
import com.sailfish.springbootdemo.service.db1.BrandTypeService;
import com.sailfish.springbootdemo.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/brandType")
@CrossOrigin
public class BrandTypeController {

    @Autowired
    private BrandTypeService brandTypeService;

    @PostMapping("/getAllBrandType")
    public Result getAllBrandType(String searchValue, Integer brandId) {
        try {
            return ResultUtil.success(brandTypeService.getAllBrandType(searchValue, brandId));
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @PostMapping("/deleteBrandTypeById")
    public Result deleteBrandTypeById(Integer brandTypeId) {
        return brandTypeService.deleteBrandTypeById(brandTypeId);
    }

    @PostMapping("/addOrUpdateBrandType")
    public Result addOrUpdateBrandType(String mode, BrandType brandType) {
        return brandTypeService.addOrUpdateBrandType(mode, brandType);
    }
}
